﻿/*
 *	(*^。^*) TFrameWork License (*^。^*)
 */

/*
 *  Title :
 *
 *  Description :
 *
 *
 *  Date :
 *
 *  Author : DengPing
 *
 *  Modify :
 */
using UnityEngine.UIElements;

namespace TFrameWork.Module.ActionEditor
{
    public class SignalInspector : EventBaseInspector
    {
        private Toggle _isDurationToggle;
        private SignalEvent _signalEvent;

        public override void Show(VisualElement root)
        {
            base.Show(root);
            _signalEvent = data as SignalEvent;

            ShowTag();
            ShowIsDration();
        }

        private void ShowIsDration()
        {
            _isDurationToggle = new Toggle("是否为持续事件");
            _isDurationToggle.value = _signalEvent.isDuration;
            _isDurationToggle.RegisterValueChangedCallback(evt =>
            {
                _signalEvent.isDuration = evt.newValue;
                if (!evt.newValue)
                {
                    _signalEvent.durationIndex = 0;
                }

                itemStyle.ResetView();
            });
            root.Add(_isDurationToggle);
        }

        protected void ShowTag()
        {
            TextField tagField = new TextField("Tag");
            tagField.value = _signalEvent.tag;
            tagField.RegisterCallback<FocusOutEvent>(p =>
            {
                if (_signalEvent.tag != tagField.value)
                {
                    _signalEvent.tag = tagField.value;
                    itemStyle.ResetView();
                }
            });
            root.Add(tagField);
        }
    }
}
